var kafile = {
    open: function (myopt) {
        if (myopt == undefined) {
            myopt = {};
        }
        var opt = {
            title: "文件上传",
            synopsis: "正在上传一个文件",
            accept: 'file',
            size: 204800,
            number: 20,
            multiple: false,
            mb: {
                title: "",
                url: "11111"
            },
            cb: function (res) {
                console.log(res);
            }
        }
        $.extend(opt, myopt);
        var uuid = ka.uuidStr();
        layui.layer.open({
            type: 1, // page 层类型
            area: ['380px', '350px'],
            title: '<i class="icon iconfont icon-cloudupload-fill" style="margin-top: 10px;text-align: center;width: 50px;height: 50px;line-height: 50px;font-size: 30px;float: left;position: absolute;background-color: #f3f1ff;border-radius: 50%;"></i>',
            offset: ['20%', '30%'],
            shade: [0.6, '#FFF'], // 点击遮罩区域，关闭弹层
            maxmin: false, // 允许全屏最小化
            anim: 0, // 0-6 的动画形式，-1 不开启
            content: `
            <div style="padding-left: 15px;padding-right: 15px;">
                <div style="font-size: 17px;font-weight: bold;margin-bottom: 5px;margin-top: 25px;line-height: 1.6;">` + opt.title + `</div>
                <div style="color: #989898;margin-top: 5px;font-size: 12px;line-height: 1.6;">` + opt.synopsis + `</div>
                <div style="margin-top: -20px;width: calc(100% - 30px);text-align: right;position: absolute;">
                    <a href="`+ opt.mb.url + `" target="_bank" style="margin-left: 5px;">` + opt.mb.title + `</a>
                </div>
                <div class="layui-upload-drag" style="display: block;margin-top: 18px;line-height: 1.6;" id="` + uuid + `">
                    <i class="layui-icon layui-icon-upload"></i> 
                    <div>点击上传，或将文件拖拽到此处</div>
                    <div class="divUploadRender"></div>
                    <div class="layui-hide" id="ID-upload-demo-preview">
                        <hr> <img src="" alt="上传成功后渲染" style="max-width: 100%">
                    </div>
                </div>
                <div>
                    <a class="layui-btn layui-btn-sm" id="` + uuid + `_btn" style="position: absolute;bottom: 10px;right: 12px;">确定上传</a>
                </div>
            </div>
            `,
            success: function () {
                var loading1UUid = "";
                layui.upload.render({
                    elem: '#' + uuid,
                    auto: false,
                    accept: opt.accept,
                    size: opt.size,
                    multiple: opt.multiple,
                    unified: true,
                    number: opt.number,
                    headers: {
                        "Authorization": kaToken.get()
                    },
                    before: function (obj) { // obj 参数同 choose
                        loading1UUid = kaMsg.loading({ type: 1 });
                    },
                    bindAction: '#' + uuid + '_btn',
                    url: kaValue.ctx() + '/common/upload', // 实际使用时改成您自己的上传接口即可。
                    error: function (index, upload, res, xhr) {
                        kaMsg.error(JSON.parse(res));
                    },
                    choose: function(obj){
                        var files = obj.pushFile();
                        obj.preview(function(index, file, result){
                            $(".divUploadRender").css("display","block");
                            $(".divUploadRender").html(file.name);
                        });
                    },
                    done: function (res) {
                        kaMsg.loadingClose(loading1UUid);
                        if (res.code == 200) {
                            layer.closeAll();
                            opt.cb(res);
                        } else {
                            kaMsg.error(res);
                        }
                    }
                });
            }
        });
    }
}